package cn.kooki.app.duobao.ui.Activity.User;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.base.BaseNavActivity;
import cn.kooki.app.duobao.data.Bean.User.bouns.BonunsCloseEvent;
import cn.kooki.app.duobao.ui.Activity.User.BonusChangeActivity;
import cn.kooki.app.duobao.ui.Adapter.TabAdapter;
import cn.kooki.app.duobao.ui.Fragment.duobaobonus.BonusItemFragment;

/**
 * Created by xiong on 2015/12/13.
 */
public class DuobaoBonusAcitivity extends BaseNavActivity implements View.OnClickListener {
    @Bind(R.id.ic_coupon)
    ImageView icCoupon;
    @Bind(R.id.ic_more)
    ImageView icMore;
    @Bind(R.id.txt_coupons_count)
    TextView txtCouponsCount;
    @Bind(R.id.layout_coupon)
    RelativeLayout layoutCoupon;
    @Bind(R.id.tabs)
    TabLayout tabs;
    @Bind(R.id.view_pager)
    ViewPager viewPager;
    private BonusItemFragment notuse;
    private BonusItemFragment used;
    private TabAdapter adapter;

    @Override
    public void setLayoutContainerView() {
        setContainerView(R.layout.activity_duobao_bonus);
        ButterKnife.bind(this);
    }

    @Override
    protected void afterView() {
        topTextCenter.setText(R.string.title_activity_duobao_bonus);
        topTextCenter.setVisibility(View.VISIBLE);

        Bundle notusetype = new Bundle();
        notusetype.putInt("type", BonusItemFragment.NOTUSE_TYPE);

        Bundle useedtype = new Bundle();
        useedtype.putInt("type", BonusItemFragment.USEED_TYPE);
        notuse = new BonusItemFragment();
        used = new BonusItemFragment();
        notuse.setArguments(notusetype);
        used.setArguments(useedtype);
        adapter = new TabAdapter(getSupportFragmentManager());
        adapter.addFragment(notuse, getString(R.string.duobao_bonus_status_enable));
        adapter.addFragment(used, getString(R.string.duobao_bonus_status_overdue));
        viewPager.setOffscreenPageLimit(2);
        viewPager.setAdapter(adapter);
        tabs.setupWithViewPager(viewPager);
        actionEdit.setText(R.string.menu_bonus_exchange);
        actionEdit.setTextColor(getResources().getColor(R.color.blue));
        actionEdit.setVisibility(View.GONE);
        actionEdit.setOnClickListener(this);
    }


    public void onEventMainThread(BonunsCloseEvent event) {
        finish();
    }

    @Override
    public void onClick(View v) {
        intent(BonusChangeActivity.class);
    }
}
